home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / gs261src.zip / GDEVEGAA.ASM < prev    next >
Assembly Source File  |  1993-05-13  |  7KB  |  279 lines

  1. ;    Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2. ;
  3. ; This file is part of Ghostscript.
  4. ;
  5. ; Ghostscript is distributed in the hope that it will be useful, but
  6. ; WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. ; to anyone for the consequences of using it or for whether it serves any
  8. ; particular purpose or works at all, unless he says so in writing.  Refer
  9. ; to the Ghostscript General Public License for full details.
  10. ;
  11. ; Everyone is granted permission to copy, modify and redistribute
  12. ; Ghostscript, but only under the conditions described in the Ghostscript
  13. ; General Public License.  A copy of this license is supposed to have been
  14. ; given to you along with Ghostscript so you can know your rights and
  15. ; responsibilities.  It should be in a file named COPYING.  Among other
  16. ; things, the copyright notice and this notice must be preserved on all
  17. ; copies.
  18.  
  19. ; gdevegaasm.asm
  20. ; Assembly code for Ghostscript PC frame buffer driver
  21.  
  22. gdevegaasm_TEXT    SEGMENT    BYTE PUBLIC 'CODE'
  23.     ASSUME    CS:gdevegaasm_TEXT
  24.  
  25. ; Note: Turbo C uses si and di for register variables, so
  26. ; we have to preserve them.
  27.  
  28. ; Normal entry and exit.  Arguments are relative to bp.
  29. enterp    macro
  30.     push    bp
  31.     mov    bp,sp
  32.     x = 6                ; offset of arguments,
  33.                     ; large code model
  34.     endm
  35. leavep    macro
  36.     pop    bp
  37.     endm
  38. ; Fast entry and exit, for procedures that don't use bx until
  39. ; they've fetched all their arguments.  Arguments are relative to ss:bx.
  40. enterf    macro
  41.     mov    bx,sp
  42.     x = 4                ; offset of arguments,
  43.                     ; large code model
  44.     endm
  45. leavef    macro
  46.     endm
  47.  
  48. ; Fast call to VESA set-page routine.
  49. ; void vesa_call_set_page(void (*set_page_proc)(int), int page_no, int win_no)
  50.     PUBLIC    _vesa_call_set_page
  51. _vesa_call_set_page proc far
  52.     enterf
  53.     mov ax,4f05h
  54.     mov dx,ss:[bx+x+4]            ; page_no
  55.     push ss:[bx+x+2]            ; set_page_proc
  56.     push ss:[bx+x]
  57.     mov bx,ss:[bx+x+6]            ; win_no
  58.     ret
  59. _vesa_call_set_page endp
  60.  
  61. ; Structure for operation parameters.
  62. ; Note that this structure is shared with C code.
  63. ; Not all parameters are used for every operation.
  64. ; typedef struct rop_params_s {
  65. p_dest    equ    0    ; fb_ptr dest;    /* pointer to frame buffer */
  66. p_draster equ    4    ; int draster;    /* raster of frame buffer */
  67. p_src    equ    6    ; const byte far *src; /* pointer to source data */
  68. p_sraster equ    10    ; int sraster;    /* source raster */
  69. p_width    equ    12    ; int width;    /* width in bytes */
  70. p_height equ    14    ; int height;    /* height in scan lines */
  71. p_shift equ    16    ; int shift;    /* amount to right shift source */
  72. p_invert equ    18    ; int invert;    /* 0 or -1 to invert source */
  73. p_data    equ    20    ; int data;    /* data for fill */
  74. ; } rop_params;
  75.  
  76. ; void memsetcol(rop_params _ss *rop)
  77. ; {    byte far *addr = rop->dest;
  78. ;    int yc = rop->height;
  79. ;    while ( yc-- )
  80. ;     { byte discard = *addr;
  81. ;       *addr = rop->data;
  82. ;       addr += rop->draster;
  83. ;     }
  84. ; }
  85.     PUBLIC    _memsetcol
  86. _memsetcol proc    far
  87.     enterf
  88.     push    ds
  89.     mov    ax,ss
  90.     mov    ds,ax
  91.     mov    bx,[bx+x]            ; rop
  92.     mov    cx,[bx].p_height
  93.     jcxz    msc0                ; height == 0
  94.     mov    ax,[bx].p_data
  95.     mov    dx,[bx].p_draster
  96.     lds    bx,[bx].p_dest
  97. ; Unroll the loop -- two copies.
  98.     inc    cx        ;round up to nearest word.  cx>=2 now.
  99.     shr    cx,1        ;make byte count into word count.
  100.     jnc    msc2        ;if it had been odd, do a half word first.
  101. msc1:    mov    ah,[bx]
  102.     mov    [bx],al
  103.     add    bx,dx
  104. msc2:    mov    ah,[bx]
  105.     mov    [bx],al
  106.     add    bx,dx
  107.     loop    msc1
  108.     pop    ds
  109. msc0:    leavef
  110.     ret
  111. _memsetcol ENDP
  112.  
  113. ; void memsetrect(rop_params _ss *rop)
  114. ; {    byte far *addr = rop->dest;
  115. ;    int yc = rop->height;
  116. ;    while ( yc-- )
  117. ;     { int cnt = rop->width;
  118. ;       while ( cnt-- ) *addr++ = rop->data;
  119. ;       addr += rop->drast - rop->width;
  120. ;     }
  121. ; }
  122.     PUBLIC    _memsetrect
  123. _memsetrect proc    far
  124.     enterf
  125.     push    ds
  126.     mov    ax,ss
  127.     mov    ds,ax
  128.     mov    bx,[bx+x]            ; rop
  129.     mov    cx,[bx].p_height
  130.     jcxz    msr0                ; height == 0
  131.     push    si
  132.     push    di
  133.     mov    ax,[bx].p_data
  134.     les    di,[bx].p_dest
  135.     cld
  136.     mov    dx,[bx].p_draster
  137.     mov    si,cx                ; si = height
  138.     mov    cx,[bx].p_width
  139.     sub    dx,cx
  140.     cmp    cx,10
  141.     ja    msrl                ; large count, use fast loop
  142. ; Small count, rep stosb is faster.
  143. msrs:    mov    cx,[bx].p_width
  144.     rep    stosb
  145.     add    di,dx
  146.     dec    si                ; count reps
  147.     jnz    msrs
  148.     pop    di
  149.     pop    si
  150. msr0:    pop    ds
  151.     leavef
  152.     ret
  153. ; Large count, loop by words rather than bytes.
  154. msrl:    mov    ah,al            ;we may be storing words...
  155. msr1:    mov    cx,[bx].p_width
  156.     test    di,1            ;test for an even address
  157.     je    msr2            ;if even, we can store words.
  158.     stosb                ;otherwise we need to even it out.
  159.     dec    cx            ;(cx is at least one here)
  160. msr2:    shr    cx,1            ;convert byte count into word count
  161.     rep    stosw            ;store them puppies as fast as we can.
  162.     jnc    msr3            ;if an odd number, store it, too.
  163.     stosb                ;(no need to dec cx here).
  164. msr3:    add    di,dx
  165.     dec    si            ; count reps
  166.     jnz    msr1
  167.     pop    di
  168.     pop    si
  169.     pop    ds
  170.     leavef
  171.     ret
  172. _memsetrect ENDP
  173.  
  174. ; void memrwcol(rop_params _ss *rop)
  175. ; {    byte far *dp = rop->dest;
  176. ;    const byte far *sp = rop->src;
  177. ;    int yc = rop->height;
  178. ;    int shift = rop->shift;
  179. ;    while ( yc-- )
  180. ;     { byte discard = *dp;
  181. ;       *dp = ((*sp >> shift) + (*sp << (8 - shift))) ^ rop->invert;
  182. ;       dp += rop->draster, sp += rop->sraster;
  183. ;     }
  184. ; }
  185.     PUBLIC    _memrwcol
  186. _memrwcol proc far
  187.     enterp
  188.     push    ds
  189.     mov    ax,ss
  190.     mov    ds,ax
  191.     mov    bx,[bp+x]            ; rop
  192.     cmp    word ptr [bx].p_height,0
  193.     jz    short mrw0
  194.     push    si
  195.     push    di
  196. ; Register usage:
  197. ;   ds:si = sp, es:di = dp, bx = sraster, dx = draster, cl = shift,
  198. ;   ch = invert, ah = low byte of yc.
  199.     push    [bx].p_height
  200.     mov    dx,[bx].p_draster
  201.     mov    ax,[bx].p_sraster
  202.     mov    cl,[bx].p_shift
  203.     mov    ch,[bx].p_invert
  204.     les    di,[bx].p_dest
  205.     lds    si,[bx].p_src
  206.     mov    bx,ax
  207.     mov    ah,[bp-8]            ; low byte of yc
  208.     test    ah,ah
  209.     jz    mrw2
  210. mrw1:    mov    al,[si]
  211.     ror    al,cl
  212.     xor    al,ch
  213.     xchg    es:[di],al
  214.     add    si,bx
  215.     add    di,dx
  216.     dec    ah
  217.     jnz    mrw1
  218. mrw2:    dec    byte ptr [bp-7]            ; high byte of yc
  219.     jge    mrw1
  220.     add    sp,2                ; pop yc
  221.     pop    di
  222.     pop    si
  223. mrw0:    pop    ds
  224.     leavep
  225.     ret
  226. _memrwcol ENDP
  227.  
  228. ; void memrwcol2(rop_params _ss *rop)
  229. ; {    byte far *dp = rop->dest;
  230. ;    const byte far *sp = rop->src;
  231. ;    int yc = rop->height;
  232. ;    int shift = rop->shift;
  233. ;    while ( yc-- )
  234. ;     { byte discard = *dp;
  235. ;       *dp = ((sp[1] >> shift) + (*sp << (8 - shift))) ^ rop->invert;
  236. ;       dp += rop->draster, sp += rop->sraster;
  237. ;     }
  238. ; }
  239.     PUBLIC    _memrwcol2
  240. _memrwcol2 proc far
  241.     enterp
  242.     push    ds
  243.     mov    ax,ss
  244.     mov    ds,ax
  245.     mov    bx,[bp+x]            ; rop
  246.     cmp    word ptr [bx].p_height,0
  247.     jz    short mrw20
  248.     push    si
  249.     push    di
  250. ; Register usage:
  251. ;   ds:si = sp, es:di = dp, bx = sraster, dx = draster, cl = shift,
  252. ;   ch = invert.
  253.     push    [bx].p_height
  254.     mov    dx,[bx].p_draster
  255.     mov    ax,[bx].p_sraster
  256.     mov    cl,[bx].p_shift
  257.     mov    ch,[bx].p_invert
  258.     les    di,[bx].p_dest
  259.     lds    si,[bx].p_src
  260.     mov    bx,ax
  261. mrw21:    mov    ax,[si]                ; bytes are in wrong order...
  262.     ror    ax,cl
  263.     xor    ah,ch                ; ... so result is in ah
  264.     xchg    es:[di],ah
  265.     add    si,bx
  266.     add    di,dx
  267.     dec    word ptr [bp-8]            ; yc
  268.     jg    mrw21
  269.     add    sp,2                ; pop yc
  270.     pop    di
  271.     pop    si
  272. mrw20:    pop    ds
  273.     leavep
  274.     ret
  275. _memrwcol2 ENDP
  276.  
  277. gdevegaasm_TEXT    ENDS
  278.     END
  279.